﻿using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.ServiceModel.Activation;
using System.Collections.Generic;
using System.Text;

namespace SilverQueryDemo.Web
{
	[ServiceContract(Namespace = "")]
	[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
	public class BootClosetService
	{
		[OperationContract]
		[WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "boot/{sku}")]
		public BootStyle GetBoot(string sku)
		{
			BootStyle boot;
			if (_db.TryGetValue(Int32.Parse(sku), out boot))
				return boot;

			return null;
		}

		[OperationContract]
		[WebGet(ResponseFormat=WebMessageFormat.Json, UriTemplate="/sizes")]
		public string[] GetSizes()
		{
			return _sizes;
		}

		[OperationContract]
		[WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "/term/{term}")]
		public string GetTerm(string term)
		{
			string def;
			if (_termLookup.TryGetValue(term.ToLower(), out def))
				return def;
			return "Unknown term";
		}

		[OperationContract]
		[WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "/boots")]
		public Dictionary<int, string> GetBootStyles()
		{
			var boots = new Dictionary<int, string>();
			foreach (int key in _db.Keys)
			{
				boots[key] = _db[key].Name;
			}
			return boots;
		}

		private Dictionary<int, BootStyle> _db = new Dictionary<int, BootStyle>()
		{
			{ 7141922, new BootStyle() { 
				Sku=7141922, 
				Name="Chippewa Harness Boot", 
				Height="13 inches", 
				Lining="Leather", 
				Colors= new string[]{ "Black", "Crazy Horse"}, 
				Price=187.00, 
				Features="<abbr>Full-grain</abbr> leather uppers. Leather lining. <abbr>Vibram</abbr> sole. <abbr>Goodyear welt</abbr>."}
			},
			{ 7177382, new BootStyle() { 
				Sku=7177382, 
				Name="Caterpillar Tradesman Work Boot", 
				Height="6 inches", 
				Lining="Leather", 
				Colors= new string[]{ "Honey", "Peanut"}, 
				Price=87.00, 
				Features="<abbr>Full-grain</abbr> <abbr>oil-tanned</abbr> leather. Nylon mesh lining. Ortholite sock liner. EVA midsole. T84V Rubberlon outsole."}
			},
			{ 7141730, new BootStyle() { 
				Sku=7141730, 
				Name="Danner Foreman Pro Work Boot", 
				Height="10 inches", 
				Lining="Leather", 
				Colors= new string[]{ "Honey", "Brown"}, 
				Price=287.00, 
				Features="Alkali-resistant <abbr>full-grain</abbr> leather. <abbr>Cambrelle</abbr> nylon lining. Fiberglass shank. <abbr>Vibram</abbr> 4014 Cristy sole. <abbr>Stitch-down</abbr> construction."}
			},
			{ 7141833, new BootStyle() { 
				Sku=7141833, 
				Name="Chippewa 17-inch Snakeproof Boot", 
				Height="17 inches", 
				Lining="Leather", 
				Colors= new string[]{ "Russet"}, 
				Price=147.00, 
				Features="<abbr>Full-grain</abbr> leather foot. 1000 Denier <abbr>Cordura</abbr> Viper cloth shaft. <abbr>Goodyear welt</abbr>. Leather Lining. Body Cushion Insole. <abbr>Vibram</abbr> Robinson Outsole."}
			},
			{ 7257914, new BootStyle() { 
				Sku=7257914, 
				Name="Danner Grouse GTX Boot", 
				Height="8 inches", 
				Lining="<abbr>Gore-Tex</abbr>", 
				Colors= new string[]{ "Brown"}, 
				Price=207.00, 
				Features="<abbr>Full-grain</abbr> leather foot. 1000 Denier <abbr>Cordura</abbr> Viper cloth shaft. <abbr>Gore-Tex</abbr> lining. Stich-down construction."}
			},
			{ 7269643, new BootStyle() { 
				Sku=7269643, 
				Name="Caterpillar Logger Boot", 
				Height="8 inches", 
				Lining="<abbr>Cambrelle</abbr>", 
				Colors= new string[]{ "Black"}, 
				Price=157.00, 
				Features="<abbr>Full-grain</abbr> leather. <abbr>Cambrelle</abbr>&reg; lining. Steel safety toe. Electrical hazard protection. Poliyou&reg; cushion insole. Rubber lug outsole."}
			}
		};

		private string[] _sizes = new string[] { "9 D", "9 EE", "9\u00BD D", "9\u00BD EE", "9\u00BD EEE", "10 EE", "10 EEE", "13 E" };

		private Dictionary<string, string> _termLookup = new Dictionary<string, string>()
		{
			{"oil-tanned", "A method of leather tanning in where oils or fats are used to cure the leather. Such leather usually very supple and has a matte or \"oily\" finish and is not generally polishable."},
			{"full-grain", "Leather which has not been altered beyond hair removal. Full-grain leather is the most genuine type of leather, as it retains all of the original texture and markings of the original hide."},
			{"vibram", "A brand of boot and shoe sole created by Vitale Bramani in the 1930's, orginally for climbing boots. The Vibram&reg; brand is recognized worldwide as the leader in high performance soling products for outdoor, dress casual, and service footwear."},
			{"goodyear welt", "The Goodyear welt is a method of attaching the sole of a shoe to the upper that is  hand-stitched and allows multiple sole replacements, extending the life of the footwear."},
			{"cambrelle", "A non-woven synthetic fabric used primarily as a lining for shoes, boots and slippers."},
			{"cordura", "A certified fabric from INVISTA used in a wide range of products from luggage and backpacks to boots, to military wear and performance apparel. Cordura¨ is resistant to abrasions, tears and scuffs."},
			{"gore-tex", "A water-proof and breathable fabric that offers superior insulating abilities in a light-weight fabric."},
			{"stitch-down", "A method of boot construction that helps seal the boot against dirt, mud, and water and maximizes flexibility."}
		};
	}

	[DataContract]
	public class BootStyle
	{
		[DataMember]
		public int Sku { get; set; }
		[DataMember]
		public string Name { get; set; }
		[DataMember]
		public string Height { get; set; }
		[DataMember]
		public string Lining { get; set; }
		[DataMember]
		public string[] Colors { get; set; }
		[DataMember]
		public double Price { get; set; }
		[DataMember]
		public string Features { get; set; }
	}
}